<script src="http://172.16.18.101/catalog/view/javascript/jquery/jquery-2.1.1.min.js" type="text/javascript"></script>
<form action="test.php" method='post'>
    <div id="product">
        <div class="radio">


            <label>
                <input type="radio" name="option[45][232]" value="2" />
                2
            </label>  
            <label>
                <input type="radio" name="option[45][232]" value="3" />
                3
            </label>

        </div>


    </div>
    <input type='submit'/>
</form>
<div id="return"></div>
<script language="javascript" type="text/javascript">

    var wsUri = "ws://echo.websocket.org/";
    var output;

    function init()
    {
        output = document.getElementById("output");
        testWebSocket();
    }

    function testWebSocket()
    {
        websocket = new WebSocket(wsUri);
        websocket.onopen = function (evt) {
            onOpen(evt)
        };
        websocket.onclose = function (evt) {
            onClose(evt)
        };
        websocket.onmessage = function (evt) {
            onMessage(evt)
        };
        websocket.onerror = function (evt) {
            onError(evt)
        };
    }

    function onOpen(evt)
    {
        writeToScreen("CONNECTED");
        doSend("WebSocket rocks");
    }

    function onClose(evt)
    {
        writeToScreen("DISCONNECTED");
    }

    function onMessage(evt)
    {
        writeToScreen('<span style="color: blue;">RESPONSE: ' + evt.data + '</span>');
        websocket.close();
    }

    function onError(evt)
    {
        writeToScreen('<span style="color: red;">ERROR:</span> ' + evt.data);
    }

    function doSend(message)
    {
        writeToScreen("SENT: " + message);
        websocket.send(message);
    }

    function writeToScreen(message)
    {
        var pre = document.createElement("p");
        pre.style.wordWrap = "break-word";
        pre.innerHTML = message;
        output.appendChild(pre);
    }

    window.addEventListener("load", init, false);

</script>

<h2>WebSocket Test</h2>

<div id="output"></div>
<script type="text/javascript">
    $(function () {
        $('.radio>label').click(function () {


            alert("click");
            $(this).parent().children().removeClass('radio-checked');
            $(this).attr('class', 'radio-checked');
            $.ajax({
                url: 'test.php',
                type: 'post',
                data: $('#product input[type=\'radio\']:checked'),
                dataType: 'html',
                beforeSend: function () {
                    //$('#button-cart').button('loading');
                },
                complete: function () {
                    //$('#button-cart').button('reset');
                },
                success: function (json) {
                    $('#return').html(json);
                    if (json['error']) {
                        if (json['error']['option']) {
                            for (i in json['error']['option']) {
                                var element = $('#input-option' + i.replace('_', '-'));

                                if (element.parent().hasClass('input-group')) {
                                    element.parent().after('<div class="text-danger">' + json['error']['option'][i] + '</div>');
                                } else {
                                    element.after('<div class="text-danger">' + json['error']['option'][i] + '</div>');
                                }
                            }
                        }

                        if (json['error']['recurring']) {
                            $('select[name=\'recurring_id\']').after('<div class="text-danger">' + json['error']['recurring'] + '</div>');
                        }

                        // Highlight any found errors
                        $('.text-danger').parent().addClass('has-error');
                    }

                    if (json['success']) {
                        $('.breadcrumb').after('<div class="alert alert-success my-product-success">' + json['success'] + '<button type="button" class="close" data-dismiss="alert">&times;</button></div>');

                        $('#cart > button').html('<i class="fa fa-shopping-cart"></i> ' + json['total']);

                        $('html, body').animate({scrollTop: 0}, 'slow');

                        $('#cart > ul').load('index.php?route=common/cart/info ul li');
                    }
                },
                error: function (xhr, ajaxOptions, thrownError) {
                    alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
                }
            });
        });
    });
</script>    